<template>
	<view class="flex-col page">
		<!-- 组局标题
		组局描述
		报名时间
		组局日期
		组局具体时
		请选择组局
		组局分类
		组局城市
		组局地点
		组局金额
		组局人数
		组局图片 -->
		<view class="flex-col group">

			<view class="flex-col group_1">
				<view class="flex-col">
					<view class="flex-row section_1">
						<text class="text_1">组局标题</text>
						<input class="text_2" type="text" v-model.trim="zuju.title" placeholder="请输入组局标题" />
					</view>
					<view class="flex-row section_1">
						<text class="text_1">组局描述</text>
						<u--textarea v-model="zuju.dec" placeholder="请输入组局描述"></u--textarea>
						<!-- <input class="text_2" type="text" v-model.trim="zuju.dec" /> -->
					</view>
					<view class="flex-row section_1" @click="zhanshi(1)">
						<text class="text_1">报名时间</text>
						<input class="text_2" type="text" disabled v-model.trim="zuju.time1"
							placeholder="请选择报名开始时间和结束时间" />
					</view>
					<view class="flex-row section_1" @click="zhanshi(2)">
						<text class="text_1">组局日期</text>
						<input class="text_2" type="text" disabled v-model.trim="zuju.time2"
							placeholder="请选择组局开始时间和结束时间" />
					</view>
					<view class="flex-row section_1">
						<text class="text_1">组局具体时间段</text>
						<input class="text_2" @click="zhanshi(3)" type="text" v-model.trim="zuju.time3"
							placeholder="请选择组局开始时间段" />

						<input class="text_2" @click="zhanshi(4)" type="text" v-model.trim="zuju.time4"
							placeholder="请选择组局结束时间段" />
					</view>
					<view class="flex-row section_1" @click="zhanshi(5)">
						<text class="text_1">组局分类</text>
						<input class="text_2" type="text" disabled v-model.trim="zuju.time2" placeholder="请选择组局分类" />
					</view>
					<view class="section_3 justify-between">
						<view class="flex-row">
							<text class="text_10">组局地点</text>
							<tm-pickersCity @confirm="selectedCity" btn-color="bg-gradient-deep-purple-accent"
								class="text_11">
								<text>{{ zuju.city ?  zuju.city : '选择组局地点' }}</text>
							</tm-pickersCity>
						</view>
						<image
							src="https://codefun-proj-user-res-1256085488.cos.ap-guangzhou.myqcloud.com/61ab188e1f655f0011bbaece/61e7d9270c0e3200129ec72c/16425844611732717437.png"
							class="image_5" />
					</view>
					<view class="flex-row section_1">
						<text class="text_1">组局金额</text>
						<input class="text_2" type="text" v-model.trim="zuju.num" placeholder="请输入组局金额" />
					</view>
					<view class="flex-row section_1">
						<text class="text_1">组局人数</text>
						<input class="text_2" type="text" v-model.trim="zuju.title" placeholder="请输入组局人数" />
					</view>
					<view class="flex-col section_4">
						<text>
							<!-- <span style="color: red;">*</span> -->
							组局图片
							<!-- <span style="font-size: 26rpx;color: #999;">(要求三张)</span> -->
						</text>

						<view class="item" v-for="(item,i) in zuju.image" :key="i">
							<image :src="item" mode="aspectFill" class="avatar"></image>
							<view class="del" @tap="del(i)">删除</view>
							<!-- 								<view class="del" @tap="del(i)" v-if="zt!=0">删除</view> -->
						</view>
						<view class="flex-col group_4" @click="upload" v-show="zuju.image.length<= 6">
							<image
								src="https://codefun-proj-user-res-1256085488.cos.ap-guangzhou.myqcloud.com/61ab188e1f655f0011bbaece/61e7d9270c0e3200129ec72c/16425844659951094858.png"
								class="image_6" />
							<image
								src="https://codefun-proj-user-res-1256085488.cos.ap-guangzhou.myqcloud.com/61ab188e1f655f0011bbaece/61e7d9270c0e3200129ec72c/16425844713277306992.png"
								class="image_7" />

							<!-- <image class="avatar" v-if="avatar" :src="avatar" mode=""></image> -->
						</view>
					</view>




				</view>

				<view class="flex-col items-center button" @click="submit">
					<text>提交</text>
				</view>

			</view>
		</view>

		<u-calendar :show="show1" mode="range" @confirm="confirm1"></u-calendar>
		<u-calendar :show="show2" mode="range" @confirm="confirm2"></u-calendar>
		<u-datetime-picker :show="show3" mode="time" @confirm="confirm3"></u-datetime-picker>
		<u-datetime-picker :show="show4" mode="time" @confirm="confirm4"></u-datetime-picker>
		<u-picker :show="show5" :columns="columns" @confirm="confirm5"></u-picker>
	</view>
</template>

<script>
	import tmPickersCity from '@/tm-vuetify/components/tm-pickersCity/tm-pickersCity.vue';
	import {
		uploadImage
	} from '@/config/utils'
	export default {
		components: {
			tmPickersCity
		},
		data() {
			return {
				zuju: {
					title: '',
					dec: '',
					time1: '',
					time2: '',
					time3: '',
					time4: '',
					femlei: '',
					city: '',
					price: '',
					num: '',
					image: []

				},
				columns: [
					['城市活动', '去户外', '主题活动']
				],
				radiolist1: [{
						name: '男',
						disabled: false
					},
					{
						name: '女',
						disabled: false
					}
				],
				radiolist2: [{
						name: '是',
						disabled: false
					},
					{
						name: '否',
						disabled: false
					}
				],
				show1: false,
				show2: false,
				show3: false,
				show4: false,
				show5: false,
				mssg: '',
				// u-radio-group的v-model绑定的值如果设置为某个radio的name，就会被默认选中
				radiovalue1: '男',
				radiovalue2: '是',
				realname: '',
				cardsn: '',
				mobile: uni.getStorageSync('user').phone,
				province: '',
				city: '',
				city1: '',
				district: '',
				age: "",
				avatar: '',
				desc: '',
				status: -1,
				flag: false,
				team: '',
				industry: '',
				advantage: ''
			};
		},
		onLoad() {

			// this.$http.post('api/personal/check/apply').then(res => {
			// 	this.status = res
			// })

		},
		methods: {
			del(e) {
				this.zuju.image.splice(e, 1);
			},
			confirm1(e) {
				console.log(e, 'hahahah');
				this.show1 = false
				this.zuju.time1 = e[0] + '-' + e[e.length - 1]
			},
			confirm2(e) {
				console.log(e, 'hahahah');
				this.show2 = false

				this.zuju.time2 = e[0] + '-' + e[e.length - 1]
			},
			confirm3(e) {
				console.log(e, 'hahahah');
				this.show3 = false

				this.zuju.time3 = e.value
			},
			confirm4(e) {
				console.log(e, 'hahahah');
				this.show4 = false

				this.zuju.time4 = e.value
			},
			confirm5(e) {
				console.log(e, 'hahahah');
				this.show5 = false

				this.zuju.fenlei = e.value
			},
			upload1() {
				uni.chooseImage({
					count: 9 - this.zuju.image.length,
					success: (res) => {
						// console.log(res);
						let {
							tempFilePaths
						} = res;



						tempFilePaths.forEach(item => {
							uploadImage(item).then(res => {
								this.zuju.image.push(res.path)
								// this.list = this.list.concat(res.path)
								console.log(res, '/*/*/*/*/');

							})
							console.log(tempFilePaths)
						})

					}
				})
			},
			goFan() {
				window.open('https://play.bozhoukeji.cn/jh5/#/')
			},
			selectedCity(e) {
				this.city = e[0] + ' ' + e[1] + ' ' + e[2]
				this.province = e[0],
					this.city1 = e[1],
					this.district = e[2],
					console.log(e)
			},
			getFileInfo(imgSrc) { //判断是否压缩
				uni.getFileInfo({
					filePath: imgSrc,
					success: (resFileInfo) => {
						if (resFileInfo.size > 1024 * 200) {
							//				压缩后大于  ↑  就继续压缩
							this.recursionCompressH5(imgSrc);
							return;
						} else {

							uploadImage(imgSrc).then(res => {
								this.zuju.image.push(res.path)
								// this.list = this.list.concat(res.path)
								console.log(res, '/*/*/*/*/');

							})
						}
					},
				});
			},
			recursionCompressH5(url) {
				uni.getImageInfo({
					src: url,
					success: (res) => {
						console.log(res);
						let canvasWidth = res.width; //图片原始长宽
						let canvasHeight = res.height;
						let img = new Image();
						img.src = res.path;
						let canvas = document.createElement("canvas");
						let ctx = canvas.getContext("2d");
						canvas.width = canvasWidth / 2;
						canvas.height = canvasHeight / 2;
						ctx.drawImage(img, 0, 0, canvasWidth / 2, canvasHeight / 2);
						canvas.toBlob((fileSrc) => {
							let imgSrc = window.URL.createObjectURL(fileSrc);
							uni.getFileInfo({
								filePath: imgSrc,
								success: (resFileInfo) => {
									if (resFileInfo.size > 1024 * 200) {
										//				压缩后大于  ↑  就继续压缩
										this.recursionCompressH5(imgSrc);
										return;
									} else {
										//小于就转化base64
										let resultBase64 = canvas.toDataURL(
											"image/png")
										// console.log(resultBase64);
										uploadImage(resultBase64).then(res => {
											this.zuju.image.push(res.path)
											// this.list = this.list.concat(res.path)
											console.log(res, '/*/*/*/*/');

										})
									}
								},
							});
						});
					}
				})
			},
			upload() {
				uni.chooseImage({
					count: 3 - this.zuju.image.length,
					success: (res) => {
						// console.log(res);
						let {
							tempFilePaths
						} = res;

						tempFilePaths.forEach(item => {
							// this.recursionCompressH5(item)
							this.getFileInfo(item)
						})
						return

						tempFilePaths.forEach(item => {
							uploadImage(item).then(res => {
								this.zuju.image.push(res.path)
								// this.list = this.list.concat(res.path)
								console.log(res, '/*/*/*/*/');

							})
							console.log(tempFilePaths)
						})

					}
				})
			},
			zhanshi(type) {
				if (type == 1) {
					this.show1 = true
				}
				if (type == 2) {
					this.show2 = true
				}
				if (type == 3) {
					this.show3 = true
				}
				if (type == 4) {
					this.show4 = true
				}
				if (type == 5) {
					this.show5 = true
				}
			},
			submit() {
				uni.showToast({
					icon: 'none',
					title: '已提交审核，请耐心等待'
				})
				setTimeout(() => {
					uni.navigateBack({
						delta: 1
					})
				}, 1000)
			}
			// 	if (!this.realname) {
			// 		uni.showToast({
			// 			icon: 'none',
			// 			title: '请输入姓名'
			// 		});
			// 		return;
			// 	}
			// 	if (!this.cardsn) {
			// 		uni.showToast({
			// 			icon: 'none',
			// 			title: '请输入身份证'
			// 		});
			// 		return;
			// 	}
			// 	if (!(/^1[3456789]\d{9}$/.test(this.mobile))) {
			// 		uni.showToast({
			// 			icon: 'none',
			// 			title: '请输入正确格式的手机号'
			// 		});
			// 		return;
			// 	}

			// 	if (!this.city) {
			// 		uni.showToast({
			// 			icon: 'none',
			// 			title: '请先选择代理城市'
			// 		});
			// 		return;
			// 	}
			// 	this.$http.post('api/personal/agency/apply', {
			// 		username: this.realname,
			// 		id_card: this.cardsn,
			// 		phone: this.mobile,
			// 		team_size: this.team,
			// 		province: this.province,
			// 		city: this.city1,
			// 		district: this.district,
			// 		trade: this.industry,
			// 		sex: this.radiovalue1,
			// 		intro: this.advantage
			// 	}).then(res => {
			// 		uni.showToast({
			// 			icon: 'none',
			// 			title: '已提交审核，请耐心等待'
			// 		})
			// 		setTimeout(() => {
			// 			uni.navigateBack({
			// 				delta: 1
			// 			})
			// 		}, 1000)
			// 	})
			// }
		}
	};
</script>

<style scoped lang="scss">
	.topsrcomage {
		width: 100%;
		height: 100%;
	}

	.tyop {
		text-align: center;
	}

	.sersdrefuia {
		height: 550rpx;
	}

	.textbackground {
		width: 90%;
		height: 70rpx;
		background-color: #A973FF;
		color: white;
		border-radius: 50rpx;
		align-items: center;
		text-align: center;
		line-height: 70rpx;
		font-size: 30rpx;
		margin: 150rpx auto;
	}

	.centerser {
		width: 80%;
		height: 650rpx;
		background-color: white;
		border-radius: 15rpx;
		margin: -60rpx auto;
	}

	.topser {
		background-color: #A973FF;
		width: 100%;
		height: 350rpx;
	}

	.boxserss {
		width: 100%;
		height: 100%;
		background-color: #f5f5f5;
	}

	.yin {
		width: 100%;
		height: 100%;
		position: fixed;
		background-color: rgba(0, 0, 0, 0.8);
		z-index: 999;

	}

	.dog {
		width: 70%;
		height: 10%;
		background-color: white;
		border-radius: 8rpx;
		margin: 100rpx auto;
		display: flex;
		align-items: center;
		justify-content: center;
	}



	.page {
		background-color: #f8f8f8;
		width: 100%;
		height: 100%;
		overflow-y: auto;

		.group {
			padding-bottom: 100rpx;
			flex: 1 1 auto;
			overflow-y: auto;
			padding-top: 20rpx;

			.image_1 {
				width: 100vw;
				height: 53.5vw;
			}

			.group_1 {
				margin-top: -10rpx;
				padding: 0 32rpx;
				position: relative;

				.button {
					margin-top: 90rpx;
					padding: 22rpx 0;
					color: rgb(255, 255, 255);
					font-size: 32rpx;
					font-weight: 500;
					line-height: 44rpx;
					white-space: nowrap;
					background-color: #A973FF;
					border-radius: 44rpx;
				}

				.section_1 {
					padding: 28rpx 24rpx;
					background-color: rgb(255, 255, 255);
					border-radius: 24rpx 24rpx 0px 0px;

					.text_1 {
						color: rgb(0, 0, 0);
						font-size: 28rpx;
						font-weight: 500;
						line-height: 40rpx;
						margin-right: 10rpx;
						white-space: nowrap;
					}

					.text_2 {
						margin-left: 48rpx;
						color: rgb(153, 153, 153);
						font-size: 28rpx;
						line-height: 40rpx;
						white-space: nowrap;
					}
				}

				.section_2 {
					padding: 24rpx 24rpx 26rpx;
					color: rgb(0, 0, 0);
					font-size: 28rpx;
					font-weight: 500;
					line-height: 40rpx;
					white-space: nowrap;
					background-color: rgb(255, 255, 255);

					.text_3 {
						margin-top: 4rpx;
					}

					.image_2 {
						width: 44rpx;
						height: 44rpx;
					}

					.image_3 {
						margin-left: 48rpx;
					}

					.text_4 {
						margin-left: 4rpx;
						margin-top: 4rpx;
					}

					.image_4 {
						margin-left: 40rpx;
					}

					.text_5 {
						margin-left: 4rpx;
						margin-bottom: 4rpx;
					}
				}

				.section_3 {
					padding: 28rpx 24rpx;
					background-color: rgb(255, 255, 255);

					.text_6 {
						color: rgb(0, 0, 0);
						font-size: 28rpx;
						font-weight: 500;
						line-height: 40rpx;
						white-space: nowrap;
					}

					.text_7 {
						margin-left: 48rpx;
						color: rgb(153, 153, 153);
						font-size: 28rpx;
						line-height: 40rpx;
						white-space: nowrap;
					}

					.text_8 {
						color: rgb(0, 0, 0);
						font-size: 28rpx;
						font-weight: 500;
						line-height: 40rpx;
						white-space: nowrap;
					}

					.text_9 {
						margin-left: 48rpx;
						color: rgb(153, 153, 153);
						font-size: 28rpx;
						line-height: 40rpx;
						white-space: nowrap;
					}

					.image_5 {
						margin-bottom: 6rpx;
						width: 32rpx;
						height: 32rpx;
					}

					.text_10 {
						color: rgb(0, 0, 0);
						font-size: 28rpx;
						font-weight: 500;
						line-height: 40rpx;
						white-space: nowrap;
					}

					.text_11 {
						margin-left: 48rpx;
						color: rgb(153, 153, 153);
						font-size: 28rpx;
						line-height: 40rpx;
						width: 450rpx;
					}
				}

				.section_4 {
					padding: 28rpx 23rpx 31rpx;
					color: rgb(0, 0, 0);
					font-size: 28rpx;
					font-weight: 500;
					line-height: 40rpx;
					white-space: nowrap;
					background-color: rgb(255, 255, 255);
					border-radius: 0px 0px 24rpx 24rpx;



					.group_4 {
						margin-top: 31rpx;
						padding: 71rpx 0 71rpx;
						position: relative;

						.image_6 {
							margin-left: 71rpx;
							width: 56rpx;
							height: 56rpx;
						}

						.image_7 {
							border-radius: 24rpx;
							width: 198rpx;
							height: 198rpx;
							position: absolute;
							left: 0;
							top: 0;
						}

						.avatar {
							border-radius: 24rpx;
							position: absolute;
							width: 198rpx;
							height: 198rpx;
							position: absolute;
							left: 0;
							top: 0;
							z-index: 9;
						}
					}
				}
			}
		}
	}

	.BGImage1 {
		position: fixed;
		width: 100%;
		height: 100%;
		bottom: 0;
		top: 0;
		left: 0;
		z-index: -1;
	}

	.bgView {
		width: 100%;
		height: 100vh;
	}

	.bgView1 {
		width: 690rpx;
		height: 581rpx;
		// background: #FFFFFF;
		border-radius: 20rpx;
		margin: 15vh auto 0;
		// border: 10rpx solid #1E8554;

		.button {
			margin-top: 53rpx;
			width: 579rpx;
			height: 93rpx;
			background: #0DA17D;
			border-radius: 47rpx;
			font-size: 34rpx;
			font-family: PingFang SC;
			// font-weight: bold;
			color: #FFFFFF;
		}
	}

	.image {
		width: 284rpx;
		height: 228rpx;
	}

	.title {
		margin-top: 12rpx;
		font-size: 34rpx;
		font-family: PingFang SC;
		// font-weight: 500;
		color: #333333;
	}
</style>